; Optimisation file for inlining some very common sccz80 operations
; Inlines a couple of common operations
; l_gint rule saves 27T at the cost of 1 byte
; l_gintsp rule saves 35T at the cost of 2 bytes
; l_gintspsp rule saves 57T at the cost of 3 bytes
; l_pint rule saves 31T at cost of 2 bytes
; l_pint_pop rule saves 58T at cost of 3 bytes
; l_sxt rule saves 27T at the cost of 1 byte
; l_sub rule saves 27T at a cost of 1 bytes
=
;

	call	l_neg
=
	ld	a,l		;l_neg
	cpl
	ld	l,a
	ld	a,h
	cpl
	ld	h,a
	inc	hl

	call	l_sxt
=
	ld	l,a		;l_sxt
	rla
	sbc	a
	ld	h,a

	call	l_sub
=
	ex	de,hl	;l_sub
	or	a
	sbc	hl,de

	call	l_gchar
=
	ld	a,(hl)	;l_gchar
	ld	l,a
	rla
	sbc	a
	ld	h,a

	call	l_gcharsp	;
=
	add	hl,sp	;l_gcharsp
	ld	a,(hl)
	ld	l,a
	rla
	sbc	a
	ld	h,a

	call	l_gint
=
	ld	a,(hl)	;l_gint
	inc	hl
	ld	h,(hl)
	ld	l,a

	call	l_gint	;
=
	ld	a,(hl)	;l_gint
	inc	hl
	ld	h,(hl)
	ld	l,a

	call	l_gintsp	;
=
	add	hl,sp	;l_gintsp
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a

	call	l_gintspsp	;
=
	add	hl,sp	;l_gintspsp
	ld	a,(hl)
	inc	hl
	ld	h,(hl)
	ld	l,a
	push	hl

	call	l_pint
=
	ex	de,hl	;l_pint
	ld	(hl),e
	inc	hl
	ld	(hl),d
 	ex	de,hl

	call	l_pint_pop
=
	pop	de		;l_pint_pop
	ex	de,hl
	ld	(hl),e
	inc	hl
	ld	(hl),d
 	ex	de,hl

	call	l_glong		;ignore
	call	l_long_and
=
	pop	de
	ld	a,(hl)
	and	e	
	ld	e,a
	inc	hl
	ld	a,(hl)
	and	d
	ld	d,a
	inc	hl
	pop	bc
	ld	a,(hl)
	and	c
	ld	c,a
	inc	hl
	ld	a,(hl)
	and	b
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